<template>
	<el-drawer title="录像回放" v-model="visible" :size="1000" destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main>
				<scLive :src="info.liveUrl" :isLive="true" :autoplay="true" ref="video" id="live"></scLive>
				<div class="u-m-t-30">
					<el-form :model="FormData" :rules="rules" :disabled="mode=='show'" ref="dialogForm"
						label-width="100px">
						<el-form-item label="时间选择" prop="date">
							<div style="width:50%">
								<el-date-picker v-model="FormData.date" value-format="YYYY-MM-DD HH:mm:ss" type="datetimerange" range-separator="至"
								start-placeholder="开始时间" end-placeholder="结束时间" @change="changeDate"/>
							</div>
						</el-form-item>
						<!-- <el-form-item label="回放类型" prop="store">
							<el-select>
								<el-option>设备端录像</el-option>
							</el-select>
						</el-form-item> -->
					</el-form>
				</div>
			</el-main>
			<el-footer>
				<div class="u-flex u-row-center">
					<el-button type="primary" @click="submit">立即播放</el-button>
					<el-button type="" @click="visible = false">取消</el-button>
				</div>
			</el-footer>
		</el-container>
	</el-drawer>
</template>

<script>
	import scLive from '@/components/scVideo/live'
	import Rocker from './Rocker'
	export default {
		emits: ['success', 'closed'],
		components: {
			scLive,
			Rocker
		},
		data() {
			return {
				visible: false,
				info: {},
				isSaveing:false,
				spin: {
					channel: "",
					direction: "",
					id: "",
					speed: ""
				},
				date:{},
				FormData: {
					"channel": "",
					"end": "",
					"id": "",
					"inDevice": true,
					"protocol": "HTTP_HLS",
					"start": ""
				},
				//验证规则
				rules: {
					date: [{
						required: true,
						message: '请选择回放时间'
					}],
				},
			}
		},

		methods: {
			changeDate(e){
				console.log(e)
				this.FormData.start = e[0]
				this.FormData.end = e[1]
			},
			//表单提交方法
			async submit() {
				var valid = await this.$refs.dialogForm.validate().catch(() => {})
				if (!valid) {
					return false
				}
				this.isSaveing = true
				this.info.path = ''
				let data = {
					channel: this.info.channel,
					inDevice: this.FormData.inDevice,
					id: this.info.device,
					protocol: this.FormData.protocol,
					start: this.FormData.start,
					end: this.FormData.end
				}
				const res = await this.$API.api.cam.playback.post(data)

				this.isSaveing = false;
				if (res.code == 200) {
					this.info.path = res.data
					console.log(1111,res)
				} else {
					this.$alert(res.message, "提示", {
						type: 'error'
					})
				}
			},
			open() {
				this.visible = true
			},
			//表单注入数据
			setData(data) {
				this.visible = true
				console.log(data)
				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				Object.assign(this.info, data)
			}
		}
	}
</script>

<style>
</style>
